package org.example.json;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;

import java.io.IOException;

/**
 * @author: wf
 * @create: 2020/10/26 11:55
 * @description: DateTime JSON反序列化处理方式
 */
public class DateTimeDeserializer extends StdScalarDeserializer<DateTime> {
    private static final long serialVersionUID = 3616995296305009426L;

    public DateTimeDeserializer() {
        super(DateTime.class);
    }

    @Override
    public DateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        String text = jp.getText();
        DateTime parse = DateTime.parse(text, ISODateTimeFormat.dateTimeNoMillis());
        return parse;
    }
}
